package com.huirui.server.controller.admin;

import com.huirui.server.pojo.entity.OrderReturnReason;
import com.huirui.server.pojo.result.PageResult;
import com.huirui.server.pojo.result.Result;
import com.huirui.server.service.OrderReturnReasonService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/order/reason/for/return")
@Slf4j
@Validated
@Tag(name = "退货原因管理", description = "小程序退货原因相关API")
public class OrderReturnReasonController {

    @Resource
    private OrderReturnReasonService orderReturnReasonService;

    @PostMapping
    @Operation(summary = "添加退货原因")
    public Result<Void> addReturnReason(@RequestBody OrderReturnReason orderReturnReason) {
        orderReturnReasonService.saveReason(orderReturnReason);
        return Result.success();
    }

    @PutMapping
    @Operation(summary = "修改退货原因")
    public Result<Void> updateReturnReason(@RequestBody OrderReturnReason orderReturnReason) {
        orderReturnReasonService.updateReason(orderReturnReason);
        return Result.success();
    }

    @PatchMapping
    @Operation(summary = "修改可用状态")
    public Result<Void> updateReturnReasonStatus(@RequestParam Long returnReasonId, @RequestParam Integer status) {
        orderReturnReasonService.updateReturnReasonStatus(returnReasonId, status);
        return Result.success();
    }

    @GetMapping
    @Operation(summary = "获取退货原因列表")
    public Result<PageResult<OrderReturnReason>> listReturnReasons(Long page, Long pageSize) {
        PageResult<OrderReturnReason> result = orderReturnReasonService.listReturnReasons(page, pageSize);
        return Result.success(result);
    }

    @DeleteMapping
    @Operation(summary = "删除退货原因")
    public Result<Void> deleteReturnReason(@RequestParam Long returnReasonId) {
        orderReturnReasonService.deleteReturnReason(returnReasonId);
        return Result.success();
    }
}
